package com.hkd.utils;

import com.hkd.common.api.enums.AreaType;

/**
 * 检查工具
 * @author HKD
 * @date 2022/9/11 13:49
 */
public class CheckUtil {
    /**
     * 获取文件后缀
     * @param originalFilename
     * @return
     */
    public static String fileType(String originalFilename){
        int index = originalFilename.lastIndexOf(".");
        if (index==-1){
            return "";
        }
        return originalFilename.substring(index);
    }

    /**
     * 根据编码返回省市区类型
     * @param code
     * @return
     */
    public static AreaType areaType(String code){
        if ("0".equals(code.substring(1,2))) {
            return AreaType.COUNTRY;
        }
        if ("0000".equals(code.substring(2))) {
            return AreaType.PROVINCE;
        }
        if ("00".equals(code.substring(4))){
            return AreaType.CITY;
        }
        return AreaType.AREA;
    }
}
